package com.thermofisher.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.thermofisher.beans.Customer;
import com.thermofisher.mapper.CustomerMapper;
import com.thermofisher.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author py
 * @since 2020-01-13
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements
        CustomerService
{
    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public void insertCustomerData(List<Customer> customerList)
    {
        customerMapper.insertCustomerData(customerList);
    }

    @Override
    public void updateCustomerData(List<Customer> customerList)
    {
        customerMapper.updateCustomerData(customerList);
    }

    @Override
    public List<Customer> getAllCustomerNo()
    {
        return customerMapper.getAllCustomerNo();
    }

    @Override
    public List<Customer> needUpdateData(List<Customer> customerList, List<Customer> allCustomerNo)
    {
        List<Customer> list = new ArrayList<Customer>();

        for (Customer excelCU : customerList)
        {
            for (Customer tableCU : allCustomerNo)
            {
                if (tableCU.getCustomerNo() != null && excelCU.getCustomerNo() != null &&
                        tableCU.getCustomerNo().equals(excelCU.getCustomerNo()))
                {
                    list.add(excelCU);
                    break;
                }
            }
        }
        return list;
    }

    @Override
    public List<Customer> needInsertData(List<Customer> customerList, List<Customer> allCustomerNo)
    {
        List<Customer> list = new ArrayList<Customer>();
        String[] arr = new String[10000];
        for (int i = 0; i < allCustomerNo.size(); i++)
        {
            arr[i] = allCustomerNo.get(i).getCustomerNo();
        }

        for (int j = 0; j < customerList.size(); j++)
        {
            if (!Arrays.asList(arr).contains(customerList.get(j).getCustomerNo()))
            {
                list.add(customerList.get(j));
            }
        }
        return list;
    }

}
